﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ChainList
{
    public class ChainList<T>
    {
        private class Chain<E>
        {
            public E mayon;
            public Chain<E> next;
            public Chain<E> previous;

            public Chain()
            {
                mayon = default(E);
                next = null;
                previous = null;
            }
            public Chain(E elem, Chain<E> p, Chain<E> n)
            {
                mayon = elem;
                next = n;
                previous = p;
            }

            public Chain<E> Clone()
            {
                return new Chain<E>(mayon, previous, next);
            }
        }

        private int count;
        private Chain<T> noeud;
        //private Chain<T> iterator;

        public ChainList()
        {
            count = 0;
            noeud = new Chain<T>();
        }
        public void AddLast(T elem)
        {
            Chain<T> maillon = new Chain<T>(elem, noeud.previous, noeud);
            noeud.previous.next = maillon;
            noeud.previous = maillon;

            count++;
        }
        public void AddFirst(T elem)
        {
            Chain<T> maillon = new Chain<T>(elem, noeud, noeud.next);
            noeud.next.previous = maillon;
            noeud.next = maillon;

            count++;
        }

        public void Remove(int index)
        {
            Chain<T> temp = noeud;
            if (DirectionN(index))
            {
                for (int a = -1; a < index; a++)
                {
                    temp = temp.next;
                }
                
            }
            else
            {
            
            }
        }
        public void Remove(T elem)
        {
            
        }

        private void delete(Chain<T> c)
        {
            c.previous.next = c.next;
            c.next.previous = c.previous;
            c.previous = null;
            c.next = null;
            c.mayon = default(T);
        }

        public T GetItem(int index)
        {
            
        }
        public T GetItems()
        {
        
        }
        private bool DirectionN(int index)
        {
            return (count / 2 > index);
        }
    }
}
